/*
 * @Description: cutKey
 * @Author: zoeblow
 * @Email: wangfuyuan@nnuo.com
 * @Date: 2019-12-30 14:05:31
 * @LastEditors  : zoeblow
 * @LastEditTime : 2019-12-30 15:03:42
 * @FilePath: \monitor\sdk\cut\cutKey.js
 */

const fs = require("fs");
const path = require("path");

let SDK_PATH = path.resolve(__dirname, "../");
const keyMap = require("./keyMap.js");

fs.unlink("./cut/monitor_cut.js", function(error) {
  if (error) {
    console.log(error);
    return false;
  }
  console.log("<-:-:::::文件删除成功:::::-:->");
});

fs.readFile(SDK_PATH + "/monitor.js", function(err, data) {
  let dataString = data.toString();
  console.log("<-:-:::::关键字缩短开始:::::-:->");

  for (key in keyMap) {
    let replaceStr = "this." + key + " =";
    let reg = new RegExp(replaceStr, "g");
    dataString = dataString.replace(reg, "this." + keyMap[key] + " =");
    console.log(key, "=", keyMap[key]);
  }
  fs.writeFile("./cut/monitor_cut.js", dataString, err => {
    if (err) throw err;
    console.log("");
    console.log("<-:-:::::关键字缩短完成:::::-:->");
  });
});
